import QtQuick
import QtQuick.Controls 2.7
import FlatUIControls 1.0

Item {
    id: root
    property string text_color: FlatUI.nephritis
    property alias baudrate: baudrate_dd.currentIndex
    property alias data_bits: databits_dd.currentIndex
    property alias check_type: check_dd.currentIndex
    property alias stop_bits: stopbits_dd.currentIndex

    // 预留一个初始化函数，在项目集成中不一定需要在过程中设置，设置面板就隐藏, 默认初始化一个参数
    function display_init(baud, len, check, sp, fc){
        baudrate_dd.currentIndex = baud
        databits_dd.currentIndex = len
        check_dd.currentIndex = check
        stopbits_dd.currentIndex = sp
    }

    Column {
        spacing: 2
        Row {
            spacing: 20
            Text {
                leftPadding: 2
                topPadding: 2
                text: qsTr("波特率 :")
                width: 100
                height: 30
                color: text_color
                font {
                    family: FlatUI.latoLightFont.name
                    bold: true
                    pointSize: 16
                }
            }

            DropDown {
                id: baudrate_dd
                width: 200
                height: 30
                model: ["300","600","1200","2400","4800","9600","14400","19200","38400","56000","57600","115200","128000","256000","460800"]
            }
        }
        Row {
            spacing: 20
            Text {
                leftPadding: 2
                topPadding: 2
                text: qsTr("数据位 :")
                width: 100
                height: 30
                color: text_color
                font {
                    family: FlatUI.latoLightFont.name
                    bold: true
                    pointSize: 16
                }
            }

            DropDown {
                id: databits_dd
                width: 200
                height: 30
                model: ["5","6","7","8"]
            }
        }
        Row {
            spacing: 20
            Text {
                leftPadding: 2
                topPadding: 2
                text: qsTr("校验位 :")
                width: 100
                height: 30
                color: text_color
                font {
                    family: FlatUI.latoLightFont.name
                    bold: true
                    pointSize: 16
                }
            }

            DropDown {
                id: check_dd
                width: 200
                height: 30
                model: ["None","Even","Mark","Odd"]
            }
        }
        Row {
            spacing: 20
            Text {
                leftPadding: 2
                topPadding: 2
                text: qsTr("停止位 :")
                width: 100
                height: 30
                color: text_color
                font {
                    family: FlatUI.latoLightFont.name
                    bold: true
                    pointSize: 16
                }
            }

            DropDown {
                id: stopbits_dd
                width: 200
                height: 30
                model: ["1","1.5","2"]
            }
        }
        Row {
            spacing: 4
            Text {
                leftPadding: 2
                topPadding: 2
                text: qsTr("硬件流控 :")
                width: 100
                height: 30
                color: text_color
                font {
                    family: FlatUI.latoLightFont.name
                    bold: true
                    pointSize: 16
                }
            }
            ImageButton {
                id: ri
                checkable: true
                width: 40
                height: 30
                text: qsTr("RI")
            }
            ImageButton {
                id: dsr
                checkable: true
                width: 40
                height: 30
                text: qsTr("DSR")
            }
            ImageButton {
                id: cts
                checkable: true
                width: 40
                height: 30
                text: qsTr("CTS")
            }
            ImageButton {
                id: dtr
                checkable: true
                width: 40
                height: 30
                text: qsTr("DTR")
            }
            ImageButton {
                id: rts
                checkable: true
                width: 40
                height: 30
                text: qsTr("RTS")
            }
        }
    }
}
